﻿<%@ Page Title="Permission setting" Language="C#" MasterPageFile="~/Main.Master"
    AutoEventWireup="true" CodeBehind="AccessControl.aspx.cs" Inherits="CARMS.Admin.AccessControl" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

    <script language="javascript" type="text/javascript">
        function OpenCreateRoleWindown() {
            $dialog('<%=ResolveUrl("~/Admin/RoleCreate.aspx") %>', { width: 350, height: 120 }, function(result) {
                if (result == true) {
                    $get('<%=btnCreateTypeHidden.ClientID %>').click();
                    return true;
                }
                else { 
                    return false;
                }
            });
        }

        var checkingNode = null;
        function nodeChecked(sender, node, eventType) {
            if ((eventType == "checked" || eventType == "unchecked") && node != checkingNode) {
                checkChildren(node);
                 checkParent(node.getParent());
            }
        }

        function checkChildren(node) {
            for (var i = 0, I = node.getChildNodes().length; i < I; i++) {
                checkingNode = node.getChildNodes()[i];
                node.getChildNodes()[i].setChecked(node.getChecked());
                checkingNode = null;
                checkChildren(node.getChildNodes()[i]);
            }
        }
        function checkParent(node) {
            if (node == null) return;
            var exist = existCheckChild(node);
            if (node.getChecked() != exist) {
                checkingNode = node;
                node.setChecked(exist);
                checkingNode = null;
                checkParent(node.getParent());
            }
        }
        function existCheckChild(node) {
            for (var i = 0, col = node.getChildNodes(); i < col.length; i++) {
                if (col[i].getChecked()) return true;
            }
            return false;
        } 
    </script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:UpdatePanel runat="server">
        <ContentTemplate>
            <table border="0" cellpadding="0" cellspacing="5">
                <tr>
                    <td>
                        <div>
                            <asp:Button ID="btnCreateRole" runat="server" Text="Create Role"   SkinID="Button120" OnClientClick="return OpenCreateRoleWindown();" />
                            <asp:Button ID="btnCreateTypeHidden" runat="server" SkinID="Hidden" OnClick="btnSaveRole_Click" />
                        </div>
                    </td>
                    <td>
                        <div>
                            <asp:Button ID="btnSave" runat="server" Text="Save Configuration" OnClick="btnSaveActionToRole_Click"
                                SkinID="Button180" />
                            <asp:Label ID="lblMessage" runat="server" Style="color: Red; margin-left: 50px;"></asp:Label>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td align="left" valign="top">
                        <div style="float: left;">
                            <asp:ListBox ID="listRoles" runat="server" SelectionMode="Single" Width="150px" Height="400px"
                                AutoPostBack="True" OnSelectedIndexChanged="listRoles_SelectedIndexChanged">
                            </asp:ListBox>
                        </div>
                    </td>
                    <td align="left" valign="top">
                        <NineRays:FlyTreeView ID="tvActions" runat="server" SkinID="Actions" ExpandLevel="2" OnNodeEventJavascript="nodeChecked">
                        </NineRays:FlyTreeView>
                    </td>
                </tr>
            </table>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
